
public class daltonCombat {

    /**
     * @param args
     */
	
    public static void main(String[] args) {
   
    int damage;
    /*
	    for (int i = 0; i < 100; i++)
	    {
		    damage = attackDamage(3,5,0,0);
	    }
	*/
    combat();
    }
    
    public static void combat()
    {
    	int curHealth= 100;
    	int maxHealth= 100;
    	int strength = 3;
    	int weaponDamage = 5;
    	int level = 1;
    	int armor = 0;
    	double attackSpeed = 0.5;
    	//all becomes Character.health, Character.strength etc
    	double timeUntilNextAct = 0;//this stays probably
    	
    	int eCurHealth = 100;
    	int eMaxHealth = 100;
    	int eStrength =30;
    	int eWeaponDamage = 3;
    	int eLevel = 1;
    	int eArmor = 3;
    	double eAttackSpeed = 3;
    	//all becomes Creature.health, Creature.strength etc
    	double eTimeUntilNextAct = 0;//this stays probably
    	
    	
    	int flag = 0;
    	int damage = 0;
    	
    	while (flag == 0)
    	{
    		if (timeUntilNextAct <= 0) //USER ACTION
    		{
	    		damage = attackDamage(strength,weaponDamage,level,eArmor);
	    		System.out.println("You attack enemy for " + damage + " damage.");
	    		eCurHealth = eCurHealth - damage;
	    		System.out.println("Enemy Health is now: " + eCurHealth + "/" + eMaxHealth);
	    		System.out.println();
	    		timeUntilNextAct = timeUntilNextAct + attackSpeed;
    		}//right now only chooses you to attack. Lets user decided instead later.
    		 //other actions can include: spells, MOVING (should take a set time, ex: 0.5)
    		
    		else if (eTimeUntilNextAct <= 0)//ENEMY ACTION. must make work for multi enemies later
    		{
	    		damage = attackDamage(eStrength,eWeaponDamage,eLevel,armor);
	    		System.out.println("Enemy attacks you for " + damage + " damage.");
	    		curHealth = curHealth - damage;
	    		System.out.println("Your Health is now: " + curHealth + "/" + maxHealth);
	    		System.out.println();
	    		eTimeUntilNextAct = eTimeUntilNextAct + eAttackSpeed;
    		}//right now only chooses to attack, enemy may use other actions later.
   		     //other actions can include: spells, MOVING (should take a set time, ex: 0.5)
    		 //AI: move towards player if player is not adjacent
    		else
    		{
    			timeUntilNextAct = timeUntilNextAct - 0.1;
    			eTimeUntilNextAct = eTimeUntilNextAct - 0.1;
    		}
    		
    		if (curHealth <= 0)
    		{
    			System.out.println("You have died!");
    			flag = 1;
    		}
    		else if (eCurHealth <= 0)
    		{
    			System.out.println("You have defeated enemy!");
    			flag = 1;
    		}
    	}
    }
   
    //ArrayList<String> aBuffs,
    //ArrayList<String> dBuffs,
    
    public static int attackDamage(int aStrength,int aWeaponDamage,int aLevel, int dArmor)
    {
        double calcStrength = (double) aStrength;
        double calcDamage = calcStrength/2 + aWeaponDamage + randNum(aLevel,aLevel*3) - dArmor;
       
        int finalDamage = (int)calcDamage;
       
        //
        double remainder = calcDamage - (int)calcDamage;
        int percentChanceUp = (int)(remainder * 100);
        int requiredUp = randNum(1,100);
        if (percentChanceUp >= requiredUp)
        {
            finalDamage = finalDamage + 1;
        }
        //makes the damage calc account for decimal final values of damage rather than just flooring the value
        //10.4 --> 10 damage OR 11 damage, so:
        //40% of the time it deals 10 damage
        //60% of the time it deals 11 damage
        
        //System.out.print("REMAINDER IS: " + remainder + ".  ");
	    //System.out.println(finalDamage);
        return finalDamage;
    }
   
	public static int randNum(int one, int two) {
		int add = 1;
		int mod = one;

		if (one > two) {
			add = -1;
			mod = two;
		}
		return (int)(Math.random()*(Math.abs(one-two-add)))+mod;
	}
}